
var formUlala = {
	init : function(){

		/**
			 * form autofill (jQuery plugin)
			 * Version: 0.1
			 * Released: 2011-11-30
			 *
			 * Copyright (c) 2011 Creative Area
			 * Dual licensed under the MIT or GPL Version 2 licenses.
			 *
			 * Require jQuery
			 * http://jquery.com/
			 * Copyright 2011, John Resig
			 * Dual licensed under the MIT or GPL Version 2 licenses.
			 * http://jquery.org/license
			 */
			(function($){
				$.fn.extend({
					autofill: function(data, options) {
						var settings = {
								findbyname: true,
								restrict: true
							},
							self = this;

						if ( options ) {
							$.extend( settings, options );
						}

						return this.each(function() {
							$.each( data, function(k, v) {

								// switch case findbyname / findbyid

								var selector, elt;

								if ( settings.findbyname ) { // by name

									selector = '[name="'+k+'"]';
									elt      = ( settings.restrict ) ? self.find( selector ) : $( selector );

									if ( elt.length == 1 ) {
										elt.val( ( elt.attr("type") == "checkbox" ) ? [v] : v );
									} else if ( elt.length > 1 ) {
										// radio
										elt.val([v]);
									} else {
										selector = '[name="'+k+'[]"]';
										elt      = ( settings.restrict ) ? self.find( selector ) : $( selector );
										elt.each(function(){
											$(this).val(v);
										});
									}

								} else { // by id

									selector = '#'+k;
									elt      = ( settings.restrict ) ? self.find( selector ) : $( selector );

									if ( elt.length == 1 ) {
										elt.val( ( elt.attr("type") == "checkbox" ) ? [v] : v );
									} else {
										var radiofound = false;

										// radio
										elt = ( settings.restrict ) ? self.find( 'input:radio[name="'+k+'"]' ) : $( 'input:radio[name="'+k+'"]' );
										elt.each(function(){
											radiofound = true;
											if ( this.value == v ) { this.checked = true; }
										});
										// multi checkbox
										if ( !radiofound ) {
											elt = ( settings.restrict ) ? self.find( 'input:checkbox[name="'+k+'[]"]' ) : $( 'input:checkbox[name="'+k+'[]"]' );
											elt.each(function(){
												$(this).val(v);
											});
										}
									}
								}
							});
						});
					}
				});
			})(jQuery);

		formUlala.Ulala($(this));
	},
	Ulala : function(jQObj){
		var data = {
			// User Info
			"fname"                 : "simpletest",
			"postname"              : "simpletest",
			"lname"                 : "suffix",

			"email"                 : "@simpleviewinc.com",
			// All emails get set by the prompt below...
			// "contact_email"      : "@simpleviewinc.com",
			// "email_verification" : "@simpleviewinc.com",
			// "postemail"          : "@simpleviewinc.com",
			"phone"                 : "5201234567",
			"company"               : "simpleviewinc",
			// Password
			"password"              : 'password',
			"password2"             : 'password',
			"passHint"              : 'password',
			"passAnswer"            : 'password',
			// Address
			"addr1"                 : "123 Main Street",
			"city"                  : "Tucson",
			"state"                 : 'AZ',
			"state"                 : 5,
			"zip"                   : 85740,
			// Billing
			"bfname"                : "Simple",
			"blname"                : "Ton",
			"bemail"                : "uemail@simpleviewinc.com",
			"bphone"                : "520-123-4567",
			"baddr1"                : "7458 North La Cholla Boulevard",
			"bcity"                 : "Tucson",
			"bstate"                : 'AZ',
			"bstate"                : 5,
			"bzip"                  : 85741,
			// Credit Card Info
			"paymentTypeID"         : 1,
			"ccnum"                 : 4111111111111111,
			"expMonth"              : ("0" + (new Date()).getMonth()+2).slice(-2),
			"expYear"               : (new Date()).getFullYear()+1,
			"ccv"                   : "777",
			// NEW EVENTS
			title                   : 'TESTING TESTING 123',
			description             : 'This is a test description, this is ONLY a TEST description. If this were a real description, you would have been properly notified via your Description Broadcast Station. ',
			times                   : '9:30 - 4:30 pm',
			// EVENT IS One Month & One Year from Today.
			startdate               : ("0" + (new Date()).getMonth()+2).slice(-2)+"/"+(new Date()).getDate()+"/"+((new Date()).getFullYear()+1)

		};

		data.email = data.postemail =  data.contact_email = data.email_verification = prompt("What is your email?",data.email);

		// Fill it out for us.
		$('form').each(function(){
			$(this).autofill( data );
			$(this).find('input').each(function(){
				this.value = (this.value) ? this.value : "Random Data 1a2b3c"
			});
		})

	}
};

if(typeof jQuery == 'undefined'){
	// Install jQuery.
	//var temp$ = $;
	var js  = '1.8/jquery.min.js';
	var cdn = 'http://ajax.googleapis.com/ajax/libs/jquery/';
	var e   = document.createElement('script');
	var d   = new Date();
	e.setAttribute('src', cdn+js+'?'+d.getMonth());
	e.setAttribute('onload', "formUlala.init();");	// init punch when loaded.
	document.body.appendChild(e);
}else{
	formUlala.init();
}
